package src

import (
	zd "gitee.com/haifengat/zorm-dm"
)

type UUIDType string

func (UUIDType) GetDataType() string {
	return "varchar(36)"
}

type DateTimeType string

func (DateTimeType) GetDataType() string {
	return "varchar(19)"
}

// BaseColumn 是一个通用的列定义
type BaseColumn struct {
	zd.Entity
	UUID       UUIDType `zorm:"default:SYS_GUID"` // 达梦UUID
	Remark     string   `zorm:"type:varchar(1024);comment:备注"`
	InsertTime DateTimeType
	UpdateTime DateTimeType
}

// 权限定义
type Permission struct {
	App    string `zorm:"PrimaryKey;type:varchar(100);index;not null;comment:应用名"`
	URL    string `zorm:"PrimaryKey;type:varchar(100);index;not null;comment:URL"`
	Action string `zorm:"PrimaryKey;type:varchar(100);index;not null;comment:动作"`
	Enable bool   `zorm:"type:bit;index;not null;default:true;comment:是否启用"`
	BaseColumn
}

type PTypeType byte

// 策略定义
type Policy struct {
	PType        PTypeType `zorm:"PrimaryKey"`
	Role         string    `zorm:"PrimaryKey"`
	PermissionID UUIDType  `zorm:"PrimaryKey"`
	BaseColumn
}

/*
CREATE OR REPLACE  VIEW OPTIVER_SPLIT.CasbinPolicy AS
SELECT po.PType, po."ROLE" V0 , pe.APP V1, pe.URL V2, pe."ACTION" V3
FROM OPTIVER_SPLIT.POLICY po
LEFT JOIN OPTIVER_SPLIT.PERMISSION pe ON (po.PERMISSIONID = pe.UUID )
WHERE po.PTYPE = 'p'
UNION
SELECT PType, "ROLE" , PERMISSIONID , ” URL ,” "ACTION"
FROM OPTIVER_SPLIT."POLICY" p
WHERE p.PTYPE = 'g';
*/
type CasbinPolicy struct {
	PType string `zorm:"type:varchar(100);index;not null;comment:类别"`
	V0    string `zorm:"type:varchar(100);index;not null"`
	V1    string `zorm:"type:varchar(100);index;not null"`
	V2    string `zorm:"type:varchar(100);index"`
	V3    string `zorm:"type:varchar(100);index"`
	V4    string `zorm:"type:varchar(32767);index"`
	V5    string `zorm:"type:varchar(32767);index"`
	zd.Entity
}
